﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Globalization;
using System.Text;
using DB_QLSV.BusinessClassLibrary;
namespace DB_QLSV
{
    public class StudentManagement
    {
        //Score Class
        public class DataGVScoreOfStudentOnject
        {
            public String mssv { get; set; }
            public String tensv { get; set; }
            public String diemgiuaki { get; set; }
            public String diemcuoiki { get; set; }
            public String diemtrungbinh { get; set; }
        }
        // Course class
        public class DataGVSubjectObject
        {
            public String mamonhoc { get; set; }
            public String tenmonhoc { get; set; }
            public String mota { get; set; }
            public String tennganh { get; set; }
        }
        // Class class
        public class DataGVClassObject
        {
            public String malop { get; set; }
            public String tenlop { get; set; }
            public String tennganh { get; set; }
            public String tenkhoa { get; set; }
        }
        // Student class
        public class DataGVStudentObject
        {
            public String mssv { get; set; }
            public String hoten { get; set; }
            public String gioitinh { get; set; }
            public String nguyenquan { get; set; }
            public String tenlop { get; set; }
            public String nganh { get; set; }
        }
        //faculty class
        public class SearchButtonObject
        {
            public String id { get; set; }
            public String ten { get; set; }
        }
        // Nganh Class
        public class NganhObject
        {
            public String idSoNganh { get; set; }
            public String tenNganh { get; set; }
            public String khoa { get; set; }
        }
        //Class Class
        public class ClassObject
        {
            public String idLop { get; set; }
            public String tenLop { get; set; }
            public String idNganh { get; set; }
            public String idKhoaHoc { get; set; }
        }
        // function process KhoaHoc
        public class KhoaHoc
        {
            //public static List<KhoaHocObject> getKhoaHocList()
            //{
            //    List<KhoaHocObject> lst = new List<KhoaHocObject>();
            //    // query get database
            //    //end query
            //    KhoaHocObject item = new KhoaHocObject();


            //    return lst;
            //}
        }

        //fuction process Faculty
        public class Khoa
        {
        }
        //fuction process Branch
        public class Nganh
        {
            //to get all Nganh list 
        }
        //fuction process Class
        public class StudentClass
        {
            //get all Class 

        }
        //Those functions process some things relate to Score
        public class ScoreClass
        {
            //to load comboboxSearch to choose searched column.
            public static List<SearchButtonObject> initButtonSearchOnTabClass()
            {
                List<SearchButtonObject> lst = new List<StudentManagement.SearchButtonObject>();
                StudentManagement.SearchButtonObject item = new SearchButtonObject();
                item.id = "01";
                item.ten = "MSSV";
                lst.Add(item);

                SearchButtonObject item1 = new SearchButtonObject();
                item1.id = "02";
                item1.ten = "Tên Sinh Viên";
                lst.Add(item1);

                SearchButtonObject item2 = new SearchButtonObject();
                item2.id = "03";
                item2.ten = "Điểm giữa kỳ";
                lst.Add(item2);

                SearchButtonObject item3 = new SearchButtonObject();
                item3.id = "03";
                item3.ten = "Điểm cuối kỳ";
                lst.Add(item3);

                SearchButtonObject item4 = new SearchButtonObject();
                item4.id = "04";
                item4.ten = "Điểm trung bình";
                lst.Add(item4);

                return lst;
            }
            //to load comboboxSearch to choose searched column.
            public static List<SearchButtonObject> initButtonSearchOnTabStudent()
            {
                List<SearchButtonObject> lst = new List<SearchButtonObject>();
                SearchButtonObject item = new SearchButtonObject();
                item.id = "01";
                item.ten = "MSSV";
                lst.Add(item);

                SearchButtonObject item1 = new SearchButtonObject();
                item1.id = "02";
                item1.ten = "Tên Sinh Viên";
                lst.Add(item1);

                SearchButtonObject item5 = new SearchButtonObject();
                item5.id = "06";
                item5.ten = "Mã Môn Học";
                lst.Add(item5);

                SearchButtonObject item6 = new SearchButtonObject();
                item6.id = "07";
                item6.ten = "Tên Môn Học";
                lst.Add(item6);

                SearchButtonObject item2 = new SearchButtonObject();
                item2.id = "03";
                item2.ten = "Điểm giữa kỳ";
                lst.Add(item2);

                SearchButtonObject item3 = new SearchButtonObject();
                item3.id = "04";
                item3.ten = "Điểm cuối kỳ";
                lst.Add(item3);

                SearchButtonObject item4 = new SearchButtonObject();
                item4.id = "05";
                item4.ten = "Điểm trung bình";
                lst.Add(item4);

                return lst;
            }
        }
        //fuction process Subjects
        public class MonHocClass
        {
            //get all subjects
            //get subjects depend on 
            public static List<SearchButtonObject> initButtonSearch()
            {
                List<SearchButtonObject> lst = new List<StudentManagement.SearchButtonObject>();
                StudentManagement.SearchButtonObject item = new SearchButtonObject();
                item.id = "01";
                item.ten = "Mã Môn Học";
                lst.Add(item);

                SearchButtonObject item1 = new SearchButtonObject();
                item1.id = "02";
                item1.ten = "Tên Môn Học";
                lst.Add(item1);

                SearchButtonObject item2 = new SearchButtonObject();
                item2.id = "03";
                item2.ten = "Tên Ngành";
                lst.Add(item2);

                SearchButtonObject item3 = new SearchButtonObject();
                item3.id = "03";
                item3.ten = "Mô Tả";
                lst.Add(item3);

                return lst;
            }
            //get attributes into button search on student form
            public static List<SearchButtonObject> initButtonSearchOnStudentForm()
            {
                List<SearchButtonObject> lst = new List<StudentManagement.SearchButtonObject>();
                StudentManagement.SearchButtonObject item = new SearchButtonObject();
                item.id = "01";
                item.ten = "MSSV";
                lst.Add(item);

                SearchButtonObject item1 = new SearchButtonObject();
                item1.id = "02";
                item1.ten = "Tên Sinh Viên";
                lst.Add(item1);

                SearchButtonObject item2 = new SearchButtonObject();
                item2.id = "03";
                item2.ten = "Giới Tính";
                lst.Add(item2);

                SearchButtonObject item3 = new SearchButtonObject();
                item3.id = "04";
                item3.ten = "Nguyên Quán";
                lst.Add(item3);

                SearchButtonObject item4 = new SearchButtonObject();
                item4.id = "05";
                item4.ten = "Tên Lớp";
                lst.Add(item4);

                SearchButtonObject item5 = new SearchButtonObject();
                item5.id = "06";
                item5.ten = "Ngành";
                lst.Add(item5);
                return lst;
            }

            public static string RemoveDiacritics(string text)
            {
                //Normalize string using full canonical decomposition
                string normalized = text.Normalize(NormalizationForm.FormD);
                //Remove diacritics and return new string
                StringBuilder sb = new StringBuilder(text.Length);

                for (int i = 0; i < normalized.Length; i++)
                {
                    char c =normalized[i];
                    if (c == 'đ'|| c == 'Đ')
                    {
                        sb.Append('d');
                        continue;
                    }
                    if (CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.NonSpacingMark)
                        sb.Append(c);
                } 
                
                return sb.ToString();
            }
            //to get all score of student depend on informational search
            public static List<BangDiem> getAllScoreOfStudent_DependOn_Search(List<BangDiem> lstSearchAll, string _hoTen, int column)
            {
                List<BangDiem> lstHoTen = new List<BangDiem>();
                for (int j = 0; j < int.Parse(ConstantString.COLUMNAMOUNTOFSCOREOFSTUDENT); j++)
                {
                    if (column == j)
                    {
                        string list = "";
                        for (int i = 0; i < lstSearchAll.Count(); i++)
                        {
                            switch (column)
                            {
                                case 0:
                                    list = RemoveDiacritics(lstSearchAll[i].mssv);
                                    break;
                                case 1:
                                    list = RemoveDiacritics(lstSearchAll[i].tensv);
                                    break;
                                case 2:
                                    list = RemoveDiacritics(lstSearchAll[i].diemgiuaky.ToString());
                                    break;
                                case 3:
                                    list = RemoveDiacritics(lstSearchAll[i].diemcuoiky.ToString());
                                    break;
                                case 4:
                                    list = RemoveDiacritics(lstSearchAll[i].diemtrungbinh.ToString());
                                    break;
                                   
                            }
                            string input = RemoveDiacritics(_hoTen);
                            int iIndex = list.ToLower().IndexOf(input.ToLower());
                            if (iIndex >= 0)
                            {
                                lstHoTen.Add(lstSearchAll[i]);
                            }
                        }
                        return lstHoTen;
                    }
                }
                return null;
            }
            //to get all score of student in student tab depend on informational search
            public static List<BangDiem2> getAllStudent_DependOn_StudentId(List<BangDiem2> lstSearchAll, string _hoTen, int column)
            {
                List<BangDiem2> lstHoTen = new List<BangDiem2>();
                for (int j = 0; j < int.Parse(ConstantString.COLUMNAMOUNCLOLUMNTOFSCOREOFSTUDENTTAB); j++)
                {
                    if (column == j)
                    {
                        string list = "";
                        for (int i = 0; i < lstSearchAll.Count(); i++)
                        {
                            switch (column)
                            {
                                case 0:
                                    list = RemoveDiacritics(lstSearchAll[i].mssv);
                                    break;
                                case 1:
                                    list = RemoveDiacritics(lstSearchAll[i].tensv);
                                    break;
                                case 2:
                                    list = RemoveDiacritics(lstSearchAll[i].mamonhoc.ToString());
                                    break;
                                case 3:
                                    list = RemoveDiacritics(lstSearchAll[i].tenmonhoc.ToString());
                                    break;
                                case 4:
                                    list = RemoveDiacritics(lstSearchAll[i].diemgiuaky.ToString());
                                    break;
                                case 5:
                                    list = RemoveDiacritics(lstSearchAll[i].diemcuoiky.ToString());
                                    break;
                                case 6:
                                    list = RemoveDiacritics(lstSearchAll[i].diemtrungbinh.ToString());
                                    break;


                            }
                            string input = RemoveDiacritics(_hoTen);
                            int iIndex = list.ToLower().IndexOf(input.ToLower());
                            if (iIndex >= 0)
                            {
                                lstHoTen.Add(lstSearchAll[i]);
                            }
                        }
                        return lstHoTen;
                    }
                }
                return null;
            }
            //to get all subjects depend on informational search
            public static List<DataGVSubjectObject> getAllSubject_DependOn_Search(List<DataGVSubjectObject> lstSearchAll, string _hoTen, int column)
            {
                List<DataGVSubjectObject> lstHoTen = new List<DataGVSubjectObject>();
                for (int j = 0; j < int.Parse(ConstantString.COLUMNAMOUNTOFSUBJECT); j++)
                {
                    if (column == j)
                    {
                        string list = "";
                        for (int i = 0; i < lstSearchAll.Count(); i++)
                        {
                            switch (column)
                            {
                                case 0:
                                    list = RemoveDiacritics(lstSearchAll[i].mamonhoc);
                                    break;
                                case 1:
                                    list = RemoveDiacritics(lstSearchAll[i].tenmonhoc);
                                    break;
                                case 2:
                                    list = RemoveDiacritics(lstSearchAll[i].tennganh);
                                    break;
                                case 3:
                                    list = RemoveDiacritics(lstSearchAll[i].mota);
                                    break;
                            }
                            string input = RemoveDiacritics(_hoTen);
                            int iIndex = list.ToLower().IndexOf(input.ToLower());
                            if (iIndex >= 0)
                            {
                                lstHoTen.Add(lstSearchAll[i]);
                            }
                        }
                        return lstHoTen;
                    }
                }
                return null;
            }
        
            //to get all students depend on informational search
           // public static string 
            public static List<DataGVStudentObject> getAllStudent_DependOn_Search(List<DataGVStudentObject> lstSearchAll, string _hoTen, int column)
            {
                List<DataGVStudentObject> lstHoTen = new List<DataGVStudentObject>();
                for(int j=0;j< int.Parse(ConstantString.COLUMNAMOUNTOFSTUDENT);j++)
                {
                    if (column == j)
                    {
                        string list = "";
                        for (int i = 0; i < lstSearchAll.Count(); i++)
                        {
                            switch (column)
                            {
                                case 0:
                                     list = RemoveDiacritics(lstSearchAll[i].mssv);
                                     break;
                                case 1:
                                     list = RemoveDiacritics(lstSearchAll[i].hoten);
                                     break;
                                case 2:
                                     list = RemoveDiacritics(lstSearchAll[i].gioitinh);
                                     break;
                                case 3:
                                     list = RemoveDiacritics(lstSearchAll[i].nguyenquan);
                                     break;
                                case 4:
                                     list = RemoveDiacritics(lstSearchAll[i].tenlop);
                                     break;
                                case 5:
                                     list = RemoveDiacritics(lstSearchAll[i].nganh);
                                     break;
                            }
                            string input = RemoveDiacritics(_hoTen);
                            int iIndex = list.ToLower().IndexOf(input.ToLower());
                            if (iIndex >= 0)
                            {
                                lstHoTen.Add(lstSearchAll[i]);
                            }
                        }
                        return lstHoTen;
                    }
                }      
                return null;
            }
        }
    }
}
